import imagePicker from 'react-native-image-picker';
var instance = null;
export default class ImagePickUtil {
  constructor() {
    if(!instance) {
    	instance = this;
      this.isOpen = false;
    }
    return instance;
  }


  openImagePick(callback,callbackThis){
    var options = {
      title:'请选择',
      cancelButtonTitle:'取消',
      takePhotoButtonTitle:'拍照',
      chooseFromLibraryButtonTitle:'选择相册',
      quality:0.25,

      // customButtons: [
      //   {name: 'fb', title: 'Choose Photo from Facebook'},
      // ],
      storageOptions: {
        skipBackup: true,
        path: 'images'
      }
    };
    if(this.isOpen){
      return;
    }

    this.isOpen = true;

    // this.imagePicker.showImagePicker(options, (response) => { // 这样可以调用相机
    imagePicker.launchImageLibrary(options,(response)   => {
      this.isOpen = false;
      if (response.didCancel) {
        console.log('User cancelled image picker');
      }
      else if (response.error) {
        console.log('ImagePicker Error: ', response.error);
      }
      else if (response.customButton) {
        console.log('User tapped custom button: ', response.customButton);
      }
      else {
      	callback.call(callbackThis,response);
      }
    });
  }
}
new ImagePickUtil();
module.exports = instance;
